﻿using Abcd.Order.Domain.Shared.PurchaseOrder;
using Volo.Abp.Domain.Services;
using Volo.Abp.EventBus.Distributed;

namespace Abcd.Order.Domain.PurchaseOrder
{
    public class PurchaseOrderManager : DomainService, IPurchaseOrderManager
    {
        #region DI
        public IDistributedEventBus EventBus { get; }
        public PurchaseOrderManager(IDistributedEventBus eventBus)
        {
            EventBus = eventBus;
        }
        #endregion

        public async Task SubmitAsync(int commodityId, int quantity)
        {
            var orderNo = "202111070001";

            // 发布：采购单提交事件
            var eto = new PurchaseOrderSubmitedEto
            {
                OrderNo = orderNo,
                CommodityId = commodityId,
                Quantity = quantity
            };
            // TODO：当单独运行OrderHost和WarehouseHost的时候，有一条消息被OrderHost自己消费了，尚未找到原因
            await EventBus.PublishAsync(eto);
        }
    }
}
